﻿namespace Vdc.Grid
{
    using System;
    using System.Collections.Generic;

    public class GridDataSourceNeededEventArgs : EventArgs
    {
        private string filterExpression;
        private Dictionary<string, string> foreignKeysValues;
        private Vdc.Grid.Grid grid;
        private bool handledFiltering;
        private bool handledPaging;
        private bool handledSorting;
        private int maximumRows;
        private string sortExpression;
        private int startRowIndex;
        private int totalRowCount;

        public GridDataSourceNeededEventArgs(Vdc.Grid.Grid _grid, string _sortExpression, string _filterExpression, int _startRowIndex, int _maximumRows)
        {
            this.grid = _grid;
            this.sortExpression = _sortExpression;
            this.filterExpression = _filterExpression;
            this.startRowIndex = _startRowIndex;
            this.maximumRows = _maximumRows;
            this.foreignKeysValues = new Dictionary<string, string>();
        }

        public string FilterExpression
        {
            get
            {
                return this.filterExpression;
            }
        }

        public Dictionary<string, string> ForeignKeysValues
        {
            get
            {
                return this.foreignKeysValues;
            }
            set
            {
                this.foreignKeysValues = value;
            }
        }

        public bool HandledFiltering
        {
            get
            {
                return this.handledFiltering;
            }
            set
            {
                this.grid.handleDataSourceFiltering = !value;
                this.handledFiltering = value;
            }
        }

        public bool HandledPaging
        {
            get
            {
                return this.handledPaging;
            }
            set
            {
                this.grid.handleDataSourcePaging = !value;
                this.handledPaging = value;
            }
        }

        public bool HandledSorting
        {
            get
            {
                return this.handledSorting;
            }
            set
            {
                this.grid.handleDataSourceSorting = !value;
                this.handledSorting = value;
            }
        }

        public int MaximumRows
        {
            get
            {
                return this.maximumRows;
            }
            set
            {
                this.maximumRows = value;
            }
        }

        public string SortExpression
        {
            get
            {
                return this.sortExpression;
            }
        }

        public int StartRowIndex
        {
            get
            {
                return this.startRowIndex;
            }
            set
            {
                this.startRowIndex = value;
            }
        }

        public int TotalRowCount
        {
            get
            {
                return this.totalRowCount;
            }
            set
            {
                this.totalRowCount = value;
                this.grid.TotalRecords = this.totalRowCount;
            }
        }
    }
}

